package com.ling.controller;

import com.ling.bean.Msg;
import com.ling.bean.User;
import com.ling.service.QuestionUserListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author lin
 */
@Controller
public class QuestionUserListController {
    private final QuestionUserListService questionUserListService;

    @Autowired
    public QuestionUserListController(QuestionUserListService questionUserListService) {
        this.questionUserListService = questionUserListService;
    }

    //获取用户待回答的问题
    @GetMapping(value = "/getUserToDoQuestion")
    @ResponseBody
    public Msg getUserToDoQuestion(HttpSession httpSession) {
        User user = (User) httpSession.getAttribute("user");
        if (user == null) {
            return Msg.fail().add("error", "请重新登陆！！");
        }
        return Msg.success().add("toDoQuestion",questionUserListService.getToDoQuestion(user.getId()));
    }

    //问题不感兴趣
    @GetMapping(value = "/updateHasread/{questionUserListId}")
    @ResponseBody
    public Msg updateHasread(HttpSession httpSession, @PathVariable String questionUserListId) {
        User user = (User) httpSession.getAttribute("user");
        if (user == null) {
            return Msg.fail().add("error", "请重新登陆！！");
        }
        questionUserListService.updateHasread(questionUserListId);
        return Msg.success();
    }

    @GetMapping(value = "/question-todo-list")
    public String goToQuestionToDoList() {
        return "question-todo-list";
    }
}
